package com.gdufs.secondhandwebsite.dao;

import com.gdufs.secondhandwebsite.entity.Goods;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;


@SpringBootTest
public class testGoodsMapper {
    @Autowired GoodsMapper goodsMapper;
//    int DeleteGoodsByPrimaryKey(Long goodsId);
//    Goods SelectGoodsByPrimaryKey(Long goodsId);
//    List<Goods> SelectByGoodsType(String tagName);
//    int UpdateGoodsByPrimaryKey(Goods goods);
//    int UpdateGoodsByPrimaryKeySelective(Goods goods);
    @Test
    void TestCreateGoods(){
        Goods goods =new Goods();
        goods.setGoodsName("nick aie force");
        goods.setCreateUser("lu");
        goods.setGoodsImgPath("../imgs/ipad1.png");
        goods.setGoodsIntro("又买了新的pro，所以这个闲置了想卖出去");
        goods.setPostAddress("广东外语外贸大学北校区");
        goods.setOriginalPrice(2500);
        goods.setGoodsTypeName("电子产品");
        System.out.println("返回的结果是："+goodsMapper.CreateGoods(goods));
    }
    @Test
    void TestUpdateGoodsByPrimaryKeySelective(){
        Goods goods =new Goods();
        goods.setGoodsId(3L);
        goods.setOriginalPrice(50);
        goods.setGoodsName("西装外套");
        goods.setSold(true);
        goods.setWantNum(3);
        goods.setGoodsIntro("买回来发现小了，半价买给有缘人吧");
        goods.setGoodsTypeName("上衣");
        System.out.println(goodsMapper.UpdateGoodsSelective(goods));
    }
    @Test
    void TestSelectGoodsByPrimaryKey(){
        System.out.println(goodsMapper.SelectGoodsByPrimaryKey(2L));
    }
    @Test
    void TestSelectByGoodsType(){
     List<Goods> goodsList= goodsMapper.SelectByGoodsType("电子产品");
        for(Goods goods_each:goodsList){
            System.out.println(goods_each);;
        }
    }
    @Test
   void UpdateGoodsByPrimaryKey(){
        System.out.println("商品下架： ");
        System.out.println(goodsMapper.UpdateGoodsByPrimaryKey(1L,true));
    }
    @Test
    void getAllGoods(){
        List<Goods> a = goodsMapper.getAllGoods();
        for(Goods each:a){
            System.out.println(a);
        }
    }
    @Test
    void getGoodsByTypeName(){
        List<Goods> a = goodsMapper.SelectByGoodsType("电子产品");
        for(Goods each:a){
            System.out.println(a);
        }
    }

}
